package com;


import com.pojo.Employee;
import com.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class EmployeeTest {
    @Test
    public void getEmployeeByIdTest(){
        SqlSession sqlSession = MybatisUtils.getSession();
        Employee employee = sqlSession.selectOne("com.mapper.EmployeeMapper.selectByPrimaryKey",1L);
        System.out.println(employee);
        sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
    }
    @Test
    public void addEmployeeTest(){
        SqlSession sqlSession = MybatisUtils.getSession();
        Employee employee = new Employee();
        employee.setId(5);
        employee.setName("周小明");
        employee.setAge(18);
        employee.setPosition("员工");
        int a= sqlSession.insert("com.mapper.EmployeeMapper.insert",employee);
        System.out.println(a);
        sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
    }
    @Test
    public void updateEmployeeTest() {
        SqlSession sqlSession = MybatisUtils.getSession();
        Employee employee = new Employee();
        employee.setId(5);
        employee.setName("周小明");
        employee.setAge(18);
        employee.setPosition("员工");
        int a = sqlSession.update("com.mapper.EmployeeMapper.updateByPrimaryKeySelective", employee);
        System.out.println(a);
        sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
    }
    @Test
    public void deleteEmployeeTest() {
        SqlSession sqlSession = MybatisUtils.getSession();
        int a = sqlSession.delete("com.mapper.EmployeeMapper.deleteByPrimaryKey", 5L);
        System.out.println(a);
        sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
    }
}
